export default {
  // 获取路径参数
  getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    if (!window.location.href.split('?')[1]) return null;
    var r = window.location.href.split('?')[1].match(reg);
    if (r != null) return decodeURIComponent(r[2]);
    return null;
  },
  getPic(blog, page) {
    return new Promise((resolve, reject) => {
      $.get(
          "https://pixabay.com/api/?key=14401992-7f8b97218cd16287d40b8a37a&q=backgrounds&image_type=photo&orientation=horizontal&page=" +
          page
        )
        .then(res => {
          console.log(page);
          let pics = res.hits;
          if (blog && blog.length > 0) {
            blog.map((val, index) => {
              val.picture = pics[index].webformatURL;
            });
          }
          resolve(blog);
        });
    });
  }
}